<?php
/***
 * 发行人
 */
namespace app\api\controller;

use app\api\controller\BaseController;

class EntityController extends BaseController{
	/**
	*
    *列表
	**/
	public function getList(){
        $param		= input('post.');
        $token			= (input('post.token')) ? input('post.token') : '';
		$where = ' a.status=1';
		//每页记录数
		$pageSize	= (isset($param['pagesize']) and $param['pagesize']) ? $param['pagesize'] : 10;
		//当前页
		$page		= (isset($param['page']) and $param['page']) ? $param['page'] : 1;

        $data	= model('entity')->alias('a')
            ->field('a.*')
            ->where($where)
            ->order('a.create_time desc')
            ->paginate($pageSize)
            ->toArray();

		foreach ($data['data'] as $key => &$value) {
			$value['header']=$value['header']?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$value['header']):'';
            $value['photo_wall']=$value['photo_wall']?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$value['photo_wall']):'';
            $value['create_time']=date('Y-m-d H:i:s',$value['create_time']);
		}
		return json(['code'=>1,'data'=>$data]);
	}
    /**
	*
    *详情
	**/
	public function getDetail(){
        $lang			= (input('post.lang')) ? input('post.lang') : 'en';	// 语言类型
		$id		= input('post.id');
        if(empty($id)){
            return json(['code'=>0,'code_dec'=>'param error']);
        }
        $token			= (input('post.token')) ? input('post.token') : '';

        $where = 'a.id='.$id;
        $data	= db('entity')->alias('a')
        ->field('a.*')
        ->where($where)
        ->find();

        if(empty($data)){
            return json(['code'=>0,'code_dec'=>config($lang.'.lang2')[6]]);
        }
		$data['header']=$data['header']?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$data['header']):'';
        $data['photo_wall']=$data['photo_wall']?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$data['photo_wall']):'';
        $data['create_time']=date('Y-m-d H:i:s',$data['create_time']);

		return json(['code'=>1,'data'=>$data]);
	}

}
